package com.shenrongrong.controller;
//全局捕获异常
import com.shenrongrong.common.Result;
import com.shenrongrong.exception.CustomerException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception ex){
        return Result.error(ex.getMessage());
    }
//    拦截自定义异常
    @ExceptionHandler(CustomerException.class)
    @ResponseBody
    public Result customException(CustomerException ex){
        return Result.error(ex.getStatus(),ex.getMsg());
    }
}
